import { getDicts, getDict } from '@/api/admin/dict';

const common = {
  state: {
    dicts: {}
  },
  mutations: {
    SET_DICTS: (state, dicts) => {
      state.dicts = { ...state.dicts, ...dicts };
    }
  },
  actions: {
    /** 设置多个字典 */
    getDicts({ commit }, params) {
      getDicts({ code: params }).then(res => {
        commit('SET_DICTS', res.data.data);
      });
    },
    /** 设置单个字典 */
    getDict({ commit }, params) {
      getDict({ code: params }).then(res => {
        const obj = {};
        obj[params] = res.data.data;
        console.log(obj);
        commit('SET_DICTS', obj);
      });
    }
  }
};
export default common;
